<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/3 0003
 * Time: 9:30
 */
//php重定向函数

include 'publics.php';

if(!empty($_POST)){
    $username = $_POST['username'];
    $password = $_POST['password'];
    $aql1 = "select u_id,username,password,sn from user where username = '".$username."'";
    $aql = "select * from user ";
    $link = query($aql);
    var_dump($link);exit();
    $data = find($aql);
    var_dump($data);exit();
    $sn = $data['sn'];
    if(!empty($data)){
        if($data['password'] == $password){
            if($sn == 2){
                header('Refresh: 3; url=login.php');
            }else{
//                $_SESSION['username'] = $data['username'];
                $_SESSION['user'] = $data;
                header('Refresh: 3; url=message.php');
            }
        }else{
            header('Refresh: 3; url=login.php');
        }
    }else{
        header('Refresh: 3; url=login.php');
    }
}

?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="jquery-1.10.1.min.js"></script>
</head>
<style type="text/css">
    .all{
        width: 100%;
        height: 940px;
    }
    .tij{
        width: 300px;
        height: 50px;
        margin-top: 27px;
    }
    #tij{
        width: 350px;
    }
    .nest_all{
        position: fixed;
        left: 35%;
        top: 31%;
        vertical-align: middle;
        width:366px ;
        height: 278px;
    }

</style>
<body>
<div class="all">
    <div class="nest_all">
        <form action="login.php" method="post" onsubmit="return chekFrom()">
            账号：<input class="tij" type="text" name="username" id="username" value="" placeholder="请输入你的账号">
            <br>
            密码：<input class="tij" type="text" name="password" id="password" value="">
            <input type="submit" id="tij"  value="登录" class="tij" >
        </form>
    </div>
</div>
<script type="text/javascript">
    function chekFrom(){
        var username = $("#username").val();
        var password = $("#password").val();
        if(username == ''){
            alert('账号不能为空！');
            return false;
        }
        if(password == ''){
            alert('密码不能为空！');
            return false;
        }
    }
</script>
</body>
</html>